package cn.otrue.patienthealthmanager.adapter;

import java.util.List;

import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import cn.otrue.patienthealthmanager.R;
import cn.otrue.patienthealthmanager.activity.DoctorConsultActivity;
import cn.otrue.patienthealthmanager.bean.DoctorBaseinfo;
import cn.otrue.patienthealthmanager.utils.DensityUtil;

import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.display.RoundedBitmapDisplayer;

public class FindDoctorAttentionAdpater extends BaseAdapter {

	private List<DoctorBaseinfo> allDoctor;
	private LayoutInflater inflater;
	private Context context;
	private TextView tw_doctor_mingzi;
	private TextView tw_doctor_weizhi;
	private TextView tw_doctor_zhuzhi;
	private TextView tw_consult;
	private ImageView pe_head_image;

	public void ImageSet(String imgurl, ImageView img_headPhoto) {

		DisplayImageOptions options = new DisplayImageOptions.Builder()
				.showImageOnLoading(R.drawable.iv_user_photo)
				.showImageOnFail(R.drawable.iv_user_photo)
				.showImageForEmptyUri(R.drawable.iv_user_photo)
				.cacheInMemory(true)
				.cacheOnDisk(true)
				.bitmapConfig(Bitmap.Config.RGB_565)
				.displayer(
						new RoundedBitmapDisplayer(DensityUtil.dip2px(context,
								40))).build();
		ImageLoader.getInstance().displayImage(imgurl, img_headPhoto, options);
	}

	public FindDoctorAttentionAdpater(Context context,
			List<DoctorBaseinfo> allDoctor) {
		super();
		this.allDoctor = allDoctor;
		this.context = context;
		inflater = LayoutInflater.from(this.context);

	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return allDoctor.size();
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return arg0;
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return arg0;
	}

	@Override
	public View getView(int arg0, View arg1, ViewGroup arg2) {
		arg1 = inflater
				.inflate(R.layout.acticity_attention_fragment_list, null);
		pe_head_image = (ImageView) arg1.findViewById(R.id.pe_head_image);
		tw_doctor_mingzi = (TextView) arg1.findViewById(R.id.tw_doctor_mingzi);
		tw_doctor_weizhi = (TextView) arg1.findViewById(R.id.tw_doctor_weizhi);
		tw_doctor_zhuzhi = (TextView) arg1.findViewById(R.id.tw_doctor_zhuzhi);

		tw_consult = (TextView) arg1.findViewById(R.id.tw_consult);
		tw_consult.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				Intent intent = new Intent();
				intent.setClass(context, DoctorConsultActivity.class);
				context.startActivity(intent);

			}
		});

		DoctorBaseinfo doctor = allDoctor.get(arg0);
		if (doctor.getRealname() != null) {
			tw_doctor_mingzi.setText(doctor.getRealname());
		}
		if (doctor.getRealname() != null) {
			tw_doctor_weizhi.setText(doctor.getInHospital());
		}
		if (doctor.getRealname() != null) {
			tw_doctor_zhuzhi.setText(doctor.getGood_at_subject());
		}

		String url = doctor.getHeadimg();

		ImageSet(url, pe_head_image);

		return arg1;

	}

}
